/*	kd:
	
	This is kinda like the other meter, but instead of having that fancy
	interpolation business, it just draws more of a certain sprite from left
	to right.
	
	*/

struct Gc_SbarSmoothNinjaMeter ui {
	private TextureId					sprite;
	private int							offset_per_draw;
	private int							old_count;
	private int							count;
	private int							draw_count;
	
	// kd: Fader for the last caret, for when it lights up and goes out.
	private FadeTick					tail_fade;
	
	void Load (String sprite_name, int extra_offset = 0) {
		sprite			= TexMan.CheckForTexture(sprite_name, TexMan.type_any);
		vector2 size	= TexMan.GetScaledSize(sprite);
		offset_per_draw	= size.x + extra_offset;
	}
	
	void ToInventory (Gc_StatusBar bar, class <Inventory> inv) {
		int max_amount;
		
		old_count = count;
		[count, max_amount] = bar.GetAmount(inv);
	}
	
	void ToRelativeInventory (
	Gc_StatusBar bar,
	class <Inventory> inv,
	int max_sprites) {
		int max_amount;
		
		old_count = count;
		[count, max_amount] = bar.GetAmount(inv);
		count = count * max_sprites / max_amount;
	}
	
	void NextFade (int fade_tics = 5) const {
		bool light_up		= old_count < count;
		bool go_out			= count < old_count;
		
		if(light_up) {
			tail_fade.To(fade_tics);
			draw_count = count - 1;
		}
		
		else if(go_out) {
			tail_fade.To(0, from: fade_tics);
			draw_count = count;
		}
		
		tail_fade.Next();
	}
	
	void DrawBottom (Gc_StatusBar bar, int x, int y, double t) const {
		for(int i = 0; i < draw_count; i++) {
			bar.DrawTexture(
				sprite, (x, y),
				bar.DI_ITEM_LEFT_BOTTOM | bar.DI_SCREEN_BOTTOM);
			x += offset_per_draw;
		}
		
		// kd: The last caret is one that fades in and out, so it should only
		// be drawn if the fader is active.
		if(0 < tail_fade.Now()) {
			double alpha = tail_fade.RenderStandardTarget(t);
			
			bar.DrawTexture(
				sprite, (x, y),
				bar.DI_ITEM_LEFT_BOTTOM | bar.DI_SCREEN_BOTTOM,
				alpha);
		}
	}
}